import cuscmd
import time
import re
import threading
from decimal import Decimal, getcontext
class Swipe(threading.Thread):
    def __init__(self,threadId,name,currentPath):
        threading.Thread.__init__(self)
        self.threadId = threadId
        self.name = name
        self.currentPath = currentPath

    def run(self):
        displayName = self.name + "_" +self.threadId
        code=cuscmd.executeCommand('adb/adb -s '+self.threadId+' shell wm size',self.currentPath)
        psize=code.decode(encoding="utf-8")
        print(displayName+':屏幕大小：{}'.format(psize))
        matchObj=re.findall(r'\d+',psize)
        if len(matchObj) == 2:
            print(displayName+':准备滑动')
            x = Decimal(matchObj[0])
            y = Decimal(int(matchObj[1]))
            getcontext().prec = 3
            # 构建起始坐标
            smx = x/2
            smy = y/3*2
            # 构建终点坐标
            emx = x/2
            emy = y/3
            while 1==1:
                print(displayName+':我滑动了哦')
                cmdStr = 'adb/adb -s '+self.threadId+' shell input swipe '
                cmdStr = cmdStr + str(smx)+' '+str(smy)+' '+str(emx)+' '+str(emy)+' 500'
                cuscmd.executeCommand(cmdStr,self.currentPath)
                time.sleep(5)